#include "socket.h"
#include <iostream>
#include <unistd.h>

int main(int argc, char* argv[]) {
    TcpClient c = TcpClient();
    
    if (!c.connect(argv[1], atoi(argv[2]))) {
        std::cerr << "connect error" << std::endl;
        return -1;
    }

    std::string buffer;
    for (int i = 0; i < 3; i++) {
        buffer = "hello " + std::to_string(i);
        std::cout << "Sending: " << buffer << std::endl;
        
        if (!c.send(buffer)) {
            std::cerr << "Send failed" << std::endl;
            break;
        }
        
        buffer.clear();
        if (c.recv(buffer, 512)) {
            std::cout << "Received: " << buffer << std::endl;
        } else {
            std::cerr << "Receive failed or connection closed" << std::endl;
            break;
        }

        sleep(1);
    }
    return 0;
}